<?php 

class CategoryValidation {
	
	public static function sanitiseInputs() {
		
		$inputs = array();
		
		if (isset($_REQUEST['id']) && is_numeric($_REQUEST['id']))
			$inputs['id'] = $_REQUEST['id'];
		
		if (isset($_POST['submit'])) {
			$inputs['save'] = false;
			
			if (isset($_POST['txtName']) && trim($_POST['txtName']) != '') {
				$inputs['name'] = stripcslashes($_POST['txtName']);
			}
			else {
				$inputs['error'][] = 'invalid category name'; 
			}
			$inputs['status'] = oeCategory::CATEGORY_STATUS_VISIBLE;
			
			
			if (isset($_POST['cobCategoryId']) && is_numeric($_POST['cobCategoryId']) && $_POST['cobCategoryId'] > 0) {
				$category = new oeCategory($_POST['cobCategoryId']);
				if ($category->getId() > 0 && $category->isParentCategory()) {
					$inputs['categoryId'] = $category->getId(); 
				}
				else {
					$inputs['error'][] = 'invalid parent category'; 
				}
			}
			if (!isset($inputs['error'])) {
				$inputs['save'] = true;
			}
		}
		return $inputs;
	}
	
}
